package com.erainm.impala.jdbc;


import java.sql.*;

/**
 * Created by erainm on 2021/08/30/5:58 下午.
 *
 * @Description: Impala JDBC 方式查询
 */
public class ImpalaTest {
    public static void main(String[] args) throws Exception {
        // 定义连接impala的驱动和连接url
        String driver = "org.apache.hive.jdbc.HiveDriver";
        String driverUrl = "jdbc:hive2://lg02:21050/default;auth=noSasl";
        //查询的sql语句句
        String querySql = "select * from t1";
        //获取连接
        Class.forName(driver);
        //通过Drivermanager获取连接
        Connection connection = DriverManager.getConnection(driverUrl);
        PreparedStatement ps = connection.prepareStatement(querySql);

        // 执行查询
        ResultSet resultSet = ps.executeQuery();

        int columnCount = resultSet.getMetaData().getColumnCount();

        while (resultSet.next()) {
            for (int i = 0; i < columnCount; i++) {
                String string = resultSet.getString(i);
                System.out.println(string + "\t");
            }
            System.out.println();
        }
        ps.close();
        connection.close();
    }
}
